package com.fili.gui.components;


import com.fili.gui.view.DataView;

import javax.swing.*;
import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 * User: fili
 * Date: Oct 4, 2006
 * Time: 9:46:25 PM
 */
public class PanelGrid extends JComponent implements Scrollable
{
    private DataView[] uscatoares;
    private int gridX;
    private int gridY;

    public PanelGrid(int gridX, int gridY, DataView[] uscatoares)
    {
        this.gridX = gridX;
        this.gridY = gridY;
        this.uscatoares = uscatoares;

        setLayout(new GridLayout(gridY, gridX));

        for (DataView usc : uscatoares)
            add(usc);
    }

    public Dimension getPreferredSize()
    {
        Dimension d = uscatoares[0].getPreferredSize();
        return new Dimension((uscatoares.length + gridY - 1) / gridY * d.width, gridY * d.height);
    }

    public Dimension getPreferredScrollableViewportSize()
    {
        return getPreferredSize();
    }

    public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
    {
        return 25;
    }

    public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)
    {
        return 100;
    }

    public boolean getScrollableTracksViewportWidth()
    {
        return false;
    }

    public boolean getScrollableTracksViewportHeight()
    {
        return false;
    }
}
